using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CustomCMS.API;
using CustomCMS.API.Persistance;
using log4net;
using System.IO;

public partial class Upload : CustomCMSBasePage
{
	private static readonly ILog _log = LogManager.GetLogger(typeof(Upload));
	private IPersistanceProvider _provider = null;

	protected void Page_Load(object sender, EventArgs e)
	{
        try
        {
			_provider = CMSServer.GetProvider();

			string path = GetMandatoryRequestParameter("path");
			string userId = GetMandatoryRequestParameter("userId");

			for(int i = 0; i < Request.Files.Count; i++)
			{
				_provider.SetImage((Stream)Request.Files[i].InputStream, userId, Request.Files[i].FileName, path);
			}
		}
        catch (Exception ex)
        {
            Response.Write(CreateResponse(ex.Message, ResponseStatus.Fail));
			Response.StatusCode = 500;
            _log.Error(ex.ToString());
        }
	}
}
